// import { API_HOST, CPAAS_PLATFORM } from 'utils/config';
(function () {
  if (!window.PACKAGE_PUBLIC_URL && process.env.PACKAGE_PUBLIC_URL) {
    var PACKAGE_PUBLIC_URL = process.env.PACKAGE_PUBLIC_URL;
    var PACKAGE_PUBLIC_URLS = [];

    if (PACKAGE_PUBLIC_URL) {
      try {
        if (PACKAGE_PUBLIC_URL.startsWith('[')) {
          PACKAGE_PUBLIC_URLS = JSON.parse(PACKAGE_PUBLIC_URL);

          if (typeof PACKAGE_PUBLIC_URLS === 'string') {
            PACKAGE_PUBLIC_URLS = [PACKAGE_PUBLIC_URLS];
          }
        } else {
          PACKAGE_PUBLIC_URLS = PACKAGE_PUBLIC_URL.replace(/"/g, '').split(',');
        }
      } catch (e) {
        console.log(e);
        PACKAGE_PUBLIC_URLS = PACKAGE_PUBLIC_URL.replace(/"/g, '').split(',');
      }
    }

    window.PACKAGE_PUBLIC_URLS = PACKAGE_PUBLIC_URLS;
  }
})();
/**
 * 获取某个子模块加载的 PublicUrl
 * @param moduleName 子模块名, 如果为空，则表示获取 模块列表配置文件的 PublicUrl
 */


function getMicroPublicUrl() {
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
      _ref$moduleName = _ref.moduleName,
      moduleName = _ref$moduleName === void 0 ? '' : _ref$moduleName,
      _ref$microModuleScrip = _ref.microModuleScriptMap,
      microModuleScriptMap = _ref$microModuleScrip === void 0 ? null : _ref$microModuleScrip;

  var microPackagePublicUrl = process.env.PUBLIC_URL || '/';

  if (moduleName) {
    if (window.dvaApp && window.dvaApp._store) {
      var _microModuleScriptMap = microModuleScriptMap || (window.dvaApp._store.getState().microModule || {
        microModuleScriptMap: {}
      }).microModuleScriptMap;

      var moduleConfig = _microModuleScriptMap[moduleName];

      if (moduleConfig && moduleConfig.publicUrl) {
        microPackagePublicUrl = moduleConfig.publicUrl;
      }
    } else {
      microPackagePublicUrl = __webpack_public_path__;
    }
  }

  if (!microPackagePublicUrl.startsWith('/') && !microPackagePublicUrl.startsWith('http')) {
    microPackagePublicUrl = "/".concat(microPackagePublicUrl);
  }

  if (!microPackagePublicUrl.endsWith('/')) {
    microPackagePublicUrl = "".concat(microPackagePublicUrl, "/");
  }

  return microPackagePublicUrl;
}

export function getExternalMicroPublicUrlList() {
  var PACKAGE_PUBLIC_URLS = window.PACKAGE_PUBLIC_URLS || [];
  return PACKAGE_PUBLIC_URLS.map(function (url) {
    var microPackagePublicUrl = url || '/';

    if (!microPackagePublicUrl.startsWith('/') && !microPackagePublicUrl.startsWith('http')) {
      microPackagePublicUrl = "/".concat(microPackagePublicUrl);
    }

    if (!microPackagePublicUrl.endsWith('/')) {
      microPackagePublicUrl = "".concat(microPackagePublicUrl, "/");
    }

    return microPackagePublicUrl;
  });
}
export default getMicroPublicUrl;
